package com.gitee.wsl.ext.string


/**
 * Filter [this] by searching for elements that contain [substring],
 * or if string is not [String.isValid], the list itself
 * @param substring a string, that must be [String.isValid]
 * @return a resulting list
 */
fun Iterable<String>.filterBySubstring(
    substring: String?,
    ignoreCase: Boolean = false
): List<String> = if (!substring.isValid()) toList() else asSequence()
    .filter { it.contains(substring!!, ignoreCase) }
    .toList()
